package com.wei.advice;

import com.wei.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R<String> handler(Exception e) {
        log.error("系统异常: {}", e.getMessage(), e);
        return R.fail("系统异常");
    }

    @ExceptionHandler(RuntimeException.class)
    public R<String> handler(RuntimeException e) {
        log.error("运行时异常: {}", e.getMessage(), e);
        return R.fail(e.getMessage());
    }

    @ExceptionHandler(NotLoginException.class)
    public R<String> handler(NotLoginException e) {
        log.error(e.getMessage(), e);
        return R.fail(401, e.getMessage());
    }

}
